#ifndef DBINSTANCE_H
#define DBINSTANCE_H

#include "CPPLib.h"
#include "DBModule.h"
#include "DBPin.h"

namespace DB
{	
	class Pin;
	
	class Instance
	{
		friend class Module;
        public:
                typedef std::set<DB::Pin*>      pins;
                typedef pins::const_iterator    constPinsIt;
                typedef pins::iterator          pinsIt;
	private:
		Instance();
		Instance(const Instance &dbInstance);
                /// \name Interface for Instance creationm deletion and searching.
                /// \{
        public:
                /*!
                  \brief static method for creating instance in the top module, with the specified model and name.
                  \return this method returns the created instance if it succeed, otherwise 0.
                  \note Create method will throw InstanceExists exception if there is an instance with the specified name.
                 !*/
                static Instance* Create(const Module* top, const Module* model, const std::string& name);

                static Instance* Find(const Module* top, const std::string& name);
                void Destroy();

                /// \}

                /// \name Interface for manipulating on the instance
                /// \{
        public:
                /// Sets the parameter name on the instance
                /// \note if there is an instance with the name specified, it throws NameExists exception
                void Name(const std::string& name);

                const std::string& Name() const;

                constPinsIt PinBegin() const;

                constPinsIt PinEnd() const;

                /// \}
        public:
                ~Instance();

	private:
		std::string                     m_name;
		pins                            m_pins;
		const Module* const             m_model;
		const Module*                   m_topModule;
	};
}
#endif
